Embodiments described herein relate generally to synchronization and use of shared resources within a computing environment, and more particularly to methods and apparatus for providing process-safe read/write locks on a shared resource to enable multiple-read, single-write functionality.
Known methods of preserving the data integrity of a shared resource within a computing environment employ a variety of constructs. For example, some approaches employ one or more mutual exclusion (“mutex”) and/or semaphore programming constructs that together ensure that only a single process or thread may have write access to the shared resource at any given time. In such approaches, the semaphore typically maintains a count of the number of processes or threads currently reading or requesting to read from the shared resource, and the mutex allows a process or thread to write to the shared resource only when the count of reader processes or threads is zero. However, the count can be artificially high when a process that owns/has spawned a reader thread terminates ungraciously, as there is generally no mechanism for directing the semaphore to decrement the count when this occurs (since the process has terminated without warning). The artificially-high count thus causes a condition known as “starvation,” wherein a process or thread waiting to write to the shared resource is never permitted to do so since the semaphore's reader count will never fall to zero. Some known methods of overcoming this condition require the closure of all processes and/or applications accessing the shared resource, and/or restarting of the operating system.
Thus, a need exists for a read/write lock mechanism that accurately tracks the number of reader process or threads seeking to access a shared resource and gracefully handles the unexpected termination of one or more processes.